import axios from 'axios'

const instance = axios.create({
    baseURL: 'https://api.spacetraders.io/v2',
    timeout: 1000
})

instance.interceptors.request.use(
    (config) => {
        const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiU1RBUlEiLCJ2ZXJzaW9uIjoidjIuMi4wIiwicmVzZXRfZGF0ZSI6IjIwMjQtMTItMjMiLCJpYXQiOjE3MzYyMzU5OTYsInN1YiI6ImFnZW50LXRva2VuIn0.EOVE8iw1Kcfa0hXGIucA5jqsrIc5E2YjT0ul78qgoKxV1eMsaWZG8nYtOEPW_ArT18jHVRXYCkfOdmaEMaxaWgP0JevsO8huvC_VFrMilkT6gFj_I7FP9EI2SgqqS0-esVo-GnWfgbsBvvUaB3rQQxPV-5f_FsyOVa_hnQXPJ3qLaNhHHqiFsyy17CX0-rjWBP7PVV_CdshcmsZMt6LzCFxbJxLXsSoATy9FpiD-80-ylgaDGYsPz7uFfzuDSsupPhsRRSreCy6_343RzZkaOtb1VaiosFGILZ1v81dQLD0cSU_-qoV-4uTRrPFdqKI6kbN_0gn6jDDKUyG4Av-xxg'
        if (token) {
            config.headers['Authorization'] = `Bearer ${token}`
        }
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

instance.interceptors.response.use(
    response => {
        return response.data
    },
    error => {
        return Promise.reject(error)
    }
)

export default instance